library(tidyverse); library(glue)
library(huxtable)


dict_name = 'base'
narrative_dicts = readRDS('input/narrative_dicts_v2.RDS')
dict =  narrative_dicts[[dict_name]] %>% 
  sapply(function(s) str_replace_all(s, pattern = '_', replacement = ' ')) %>% 
  sapply(function(s) paste(s, collapse = ', '))


topic_names = c('War', 'Pandemic', 'Panic','Confidence',
                'Savings','Conspicuous Consumption',
                'Monetary Standard','Technology Replacing Jobs',
                'Real Estate Boom', 'Real Estate Bust', 
                'Stock Market Bubble', 'Stock Market Crash',
                'Boycotts and Evil Business', 'Wage and Labor Unions')


out = tibble(
  Narrative = topic_names,
  `Short Name` = names(dict) %>% str_replace_all('_', ' '),
  `Seed Words` = unname(dict)
) %>% 
  
  as_hux() %>% 
  set_tb_borders(everywhere, everywhere, 0.8) %>% 
  # set_bottom_border(final(1), everywhere, 0.8) %>% 
  
  set_valign(everywhere, everywhere, 'top') %>% 
  set_align('left') %>% 
  
  set_font_size(9) %>% 
  set_all_padding(0) %>% 
  
  set_col_width(c(0.2, 0.12, 0.68)) %>%
  set_width(1) %>% # width must come after col_with
  set_wrap(value = TRUE)
  


# Export
quick_xlsx(out, file = glue('output/tables/Table_1.xlsx'))
# cat(to_latex(out, tabular_only = TRUE), file = 'output/tables/Table_1.tex')

